//
//  WPTransViewModel.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/7.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTransCancelViewModel.h"
#import "WPTransCancelModel.h"

@implementation WPTransCancelViewModel
+ (void)getTransingListWithPageNumber:(NSInteger)page andWithSuccessBlock:(void (^)(NSArray *, NSInteger))success andWithFailureBlock:(void (^)(NSString *))failure {
    NSDictionary * param = @{@"memberid":[UserModel defaultUser].userID};
    [NetWorkingManager postWithUrl:@"commoditytrade/transfermanager.jhtml" requestParams:[NetWorkingManager paramsByAppendingUserInfo:param] SuccessHandler:^(id responseObject) {
        if (responseObject[@"resultType"] && [responseObject[@"resultType"] intValue]) {
            NSMutableArray * resultArr = [NSMutableArray arrayWithCapacity:0];
            if (responseObject[@"resultMsg"]&& [responseObject[@"resultMsg"] isKindOfClass:[NSArray class]]) {
                for (NSDictionary * dict in responseObject[@"resultMsg"]) {
                    WPTransCancelModel * model = [WPTransCancelModel new];
                    [model setValuesForKeysWithDictionary:dict];
                    [resultArr addObject:model];
                }
            }
            success(resultArr, responseObject[@"totalpages"] ? [responseObject[@"totalpages"] integerValue]:1);
        } else {
            if ([responseObject[@"resultMsg"] isEqualToString:@""]) {
                success(@[], 1);
            } else {
                failure(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]:@"获取网络数据失败");
            }
        }
    } failureHandler:^(NSError *error) {
        failure(error.localizedDescription);
    }];
}
+ (void)cancelTransingWithId:(NSNumber *)transid andWithSuccessBlock:(void (^)(NSString *))succes andWithFailureBlock:(void (^)(NSString *))failure {
    NSDictionary * params = @{@"saleid":transid};
    [NetWorkingManager postWithUrl:@"commoditytrade/recallTrade.jhtml" requestParams:[NetWorkingManager paramsByAppendingUserInfo:params] SuccessHandler:^(id responseObject) {
        if (responseObject[@"resultType"] && [responseObject[@"resultType"] intValue]) {
            succes(@"撤回成功");
        } else {
            failure(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]:@"撤回失败");
        }
    } failureHandler:^(NSError *error) {
        failure(error.localizedDescription);
    }];
}
@end
